"""


"""
import functools

from flask import current_app
from flask import g
from flask import session


def do_index_class(value):
    """自定义过滤器，过滤器点击排序html的class"""
    if value == 1:
        return "first"
    elif value ==2:
        return "second"
    elif value == 3:
        return "third"
    else:
        return ""


def user_login_data(view_func):
    """查询当前客户端登陆用户信息装饰器"""
    @functools.wraps(view_func)
    def wrapper(*args,**kwargs):
        user_id = session.get("user_id")
        from info.models import User
        user = None
        if user_id:
            # 根据user_id到数据库中查询用户信息
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.erroe(e)
        # 通过ｇ变量．保存用户信息，后面提供给视图使用，视图中可以通过g.user来获取数据
        g.user = user
        return view_func(*args,**kwargs)
    return wrapper

